package com.demo.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.demo.domain.Comment;
import com.demo.domain.PracticeProject;
import com.demo.domain.Reply;
import com.demo.domain.ScientificDirection;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface ReplyDao extends BaseMapper<Reply> {
//    @Select("select * from tb_reply r where r.r_id=#{rid}")
//    Reply getById(@Param("rid") Long rid);
//    增加对应id的回复的点赞数
    @Update("update tb_reply r set r.r_likes=r.r_likes+1 where r.r_id = #{id}")
    void incrementLikes(Long id);
//    减少对应id的回复的点赞数
    @Update("update tb_reply r set r.r_likes=r.r_likes-1 where r.r_id = #{id}")
    void decrementLikes(Long id);

    //计算对应id的未读消息数
    @Select("SELECT COUNT(*) AS total_count  \n" +
            "FROM tb_reply  \n" +
            "WHERE r_read_status = 0 AND r_to_uid=#{uid};")
    int countNotViewReply(Long uid);

    //更改用户的回复信息都为已查看的状态
    @Update("UPDATE tb_reply\n" +
            "SET r_read_status = 1\n" +
            "WHERE r_read_status = 0 AND r_to_uid=#{uid}")
    int updateHadViewed(Long uid);

    //获取当前回复对应的评论id
    @Select("SELECT r_cid FROM tb_reply WHERE r_to_uid=#{uid}")
    long getCommentId(Long uid);

}
